﻿<UserControl x:Class="Kokomo.Environment.Hosting.EditorHostView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
		xmlns:i="clr-namespace:System.Windows.Media.Imaging;assembly=PresentationCore"
             xmlns:env="clr-namespace:Kokomo.Environment"
			 xmlns:h="clr-namespace:Kokomo.Environment.Hosting"
             xmlns:cmd="clr-namespace:Kokomo.Environment.Commanding"
             xmlns:svc="clr-namespace:Kokomo.Environment.Services"
		xmlns:kui="xaml://kokomo/ui"
             mc:Ignorable="d" 
			 kui:DragDropHelper.DropBehavior="{Binding DropBehavior}"
             d:DesignHeight="300" d:DesignWidth="300">
	<UserControl.Resources>
		<BitmapImage x:Key="NewDocumentImage" UriSource="pack://application:,,,/Kokomo.Environment;component/images/NewDocumentHS.png"/>
		<BitmapImage x:Key="OpenDocumentImage" UriSource="pack://application:,,,/Kokomo.Environment;component/images/openHS.png"/>
		<BitmapImage x:Key="SaveDocumentImage" UriSource="pack://application:,,,/Kokomo.Environment;component/images/saveHS.png"/>
		<BitmapImage x:Key="SaveAllDocumentsImage" UriSource="pack://application:,,,/Kokomo.Environment;component/images/SaveAllHS.png"/>
		<BitmapImage x:Key="ErrorImage" UriSource="pack://application:,,,/Kokomo.Environment;component/images/error.png"/>
	</UserControl.Resources>

	<DockPanel>
		<Menu
			DockPanel.Dock="Top"
			>
			<Menu.Resources>
				<Style TargetType="{x:Type Image}">
					<Setter Property="Width" Value="16"/>
					<Setter Property="Height" Value="16"/>
				</Style>
			</Menu.Resources>
			<Menu.ItemsSource>
				<Binding Path="MainMenuItems"/>
				<!--<CompositeCollection>
						<CollectionContainer Collection="{Binding ApplicationMenuItems}"/>
						<CollectionContainer Collection="{Binding ActiveDocument.EditorMenuItemViewModels}"/>
					</CompositeCollection>-->
			</Menu.ItemsSource>
		</Menu>

		<ToolBarTray DockPanel.Dock="Top">
			<ToolBar>
				<ToolBar.Resources>
					<Style TargetType="{x:Type Image}">
						<Setter Property="Height" Value="16"/>
						<Setter Property="Width" Value="16"/>
					</Style>
					<Style TargetType="{x:Type Button}" x:Key="{x:Static ToolBar.ButtonStyleKey}">
						<Style.Triggers>
							<Trigger Property="IsEnabled" Value="False">
								<Setter Property="Opacity" Value="0.5"/>
							</Trigger>
						</Style.Triggers>
					</Style>
				</ToolBar.Resources>
				<Button Command="{Binding NewDocumentCommand}" ToolTip="{x:Static env:Messages.NewDocumentTipText}">
					<Image Source="{StaticResource NewDocumentImage}"/>
				</Button>
				<Button Command="{Binding OpenDocumentCommand}" ToolTip="{x:Static env:Messages.OpenDocumentTipText}">
					<Image Source="{StaticResource OpenDocumentImage}"/>
				</Button>
				<Button Command="{Binding SaveDocumentCommand}" ToolTip="{x:Static env:Messages.SaveDocumentTipText}">
					<Image Source="{StaticResource SaveDocumentImage}"/>
				</Button>
				<Button Command="{Binding SaveAllDocumentsCommand}" ToolTip="{x:Static env:Messages.SaveAllDocumentsTipText}">
					<Image Source="{StaticResource SaveAllDocumentsImage}"/>
				</Button>
			</ToolBar>
		</ToolBarTray>

		<kui:TabbedDocumentView
			Margin="6"
			Background="{DynamicResource {x:Static env:EditorStyleKeys.ActiveTabColorKey}}"
			ContentTemplateSelector="{x:Static env:AttributedViewTemplateSelector.Default}"
			ItemsSource="{Binding DocumentViewModels}"
			SelectedItem="{Binding DocumentManager.ActiveDocumentViewModel, Mode=TwoWay}"
			>
			<ItemsControl.ItemContainerStyle>
				<Style TargetType="{x:Type kui:DocumentItem}">
					<Setter Property="IsSelected" Value="{Binding IsActive}"/>
					<Setter Property="IsFloating" Value="{Binding IsFloating}"/>
					<Setter Property="IsDirty" Value="{Binding IsDirty}"/>
					<Setter Property="Title" Value="{Binding Title}"/>
				</Style>
			</ItemsControl.ItemContainerStyle>
			<kui:TabbedDocumentView.TabGroupStyle>
				<Style TargetType="{x:Type kui:DocumentTabGroup}">
					<Setter Property="Background" Value="{DynamicResource {x:Static env:EditorStyleKeys.ActiveTabColorKey}}"/>
				</Style>
			</kui:TabbedDocumentView.TabGroupStyle>
			<kui:TabbedDocumentView.TabTemplate>
				<DataTemplate DataType="{x:Type kui:DocumentTab}">
					<DataTemplate.Resources>
						<Style TargetType="{x:Type Button}">
							<Setter Property="Background" Value="Transparent"/>
							<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type kui:DocumentTab}}, Path=Foreground}"/>
							<Setter Property="Template">
								<Setter.Value>
									<ControlTemplate TargetType="Button">
										<Border
											Background="{TemplateBinding Background}"
											CornerRadius="3"
											Padding="3"
											>
											<ContentPresenter/>
										</Border>
									</ControlTemplate>
								</Setter.Value>
							</Setter>
							<Style.Triggers>
								<Trigger Property="IsMouseOver" Value="True">
									<Setter Property="Background" Value="{DynamicResource {x:Static env:EditorStyleKeys.WorkspaceBackgroundBrushKey}}"/>
									<Setter Property="Foreground" Value="White"/>
								</Trigger>
							</Style.Triggers>
						</Style>
					</DataTemplate.Resources>
					<StackPanel Orientation="Horizontal">
						<TextBlock
							Name="TitleBlock"
							Text="{Binding Title}"
							ToolTipService.ToolTip="{Binding Title}"
							MaxWidth="150"
							TextTrimming="CharacterEllipsis"
							/>
						<TextBlock
							Name="MultiViewBlock"
							Text="{Binding Item.MultiViewIndex, StringFormat={}:{0}}"
							Visibility="Collapsed"
							/>
						<TextBlock Name="DirtyBlock" Text="*" Visibility="Collapsed"/>
						<Button
							Command="{Binding Item.CloseCommand}"
							CommandParameter="{Binding}"
							ToolTip="{x:Static env:Messages.CloseViewTipText}"
							Margin="2"
							>
							<Path
								Stretch="Fill"
								Stroke="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
								StrokeThickness="2"
								StrokeStartLineCap="Round"
								StrokeEndLineCap="Round"
								Data="M 0,0 L 1,1 M 0,1 L 1,0"
								Width="8"
								Height="8"
								/>
						</Button>
						<Button
							Command="{x:Static kui:TabbedDocumentView.FloatCommand}"
							CommandParameter="{Binding}"
							Margin="2"
							ToolTip="{x:Static env:Messages.FloatViewTipText}"
							>
							<Path
								Stretch="Fill"
								Stroke="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
								StrokeThickness="1"
								Data="M 0,7 L 0,2 L 5,2 L 5,7 L 0,7 M 3,5 L 7,0 M 5,0 L 7,0 L 7,2"
								Width="8"
								Height="8"
								/>
						</Button>
					</StackPanel>
					<DataTemplate.Triggers>
						<DataTrigger Binding="{Binding IsDirty}" Value="true">
							<Setter TargetName="DirtyBlock" Property="Visibility" Value="Visible"/>
						</DataTrigger>
						<DataTrigger Binding="{Binding IsSelected}" Value="true">
							<Setter TargetName="TitleBlock" Property="FontWeight" Value="Bold"/>
						</DataTrigger>
						<DataTrigger Binding="{Binding Item.HasMultipleViews}" Value="True">
							<Setter TargetName="MultiViewBlock" Property="Visibility" Value="Visible"/>
						</DataTrigger>
					</DataTemplate.Triggers>
				</DataTemplate>
			</kui:TabbedDocumentView.TabTemplate>
			<!--<kui:TabbedDocumentView.FloatingWindowStyle>
				<Style TargetType="{x:Type Window}">
					<Setter Property="WindowStyle" Value="None"/>
				</Style>
			</kui:TabbedDocumentView.FloatingWindowStyle>-->
			<kui:TabbedDocumentView.FloatingWindowTemplate>
				<ControlTemplate TargetType="{x:Type Window}">
					<Grid>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto"/>
							<RowDefinition Height="*"/>
						</Grid.RowDefinitions>

						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="*"/>
								<ColumnDefinition Width="Auto"/>
								<ColumnDefinition Width="Auto"/>
							</Grid.ColumnDefinitions>
						</Grid>
						<Border Grid.Row="1" Background="{DynamicResource {x:Static env:EditorStyleKeys.WorkspaceBackgroundBrushKey}}" Padding="6">
							<AdornerDecorator>
								<h:EditorViewWrapper>
									<ContentPresenter/>
								</h:EditorViewWrapper>
							</AdornerDecorator>
						</Border>
					</Grid>
				</ControlTemplate>
			</kui:TabbedDocumentView.FloatingWindowTemplate>
		</kui:TabbedDocumentView>

	</DockPanel>
</UserControl>
